﻿using System;
using System.Collections.Generic;
using Jxym.DBUtility;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Jxym.Common.JSON;
using System.Data.SqlClient;
using Jxym.wlkc2011.Module.Default.model;
using Newtonsoft.Json.Converters;

namespace Jxym.wlkc2011.Module.Default.server.Policy
{
    public partial class PolicyList : System.Web.UI.Page
    {
        int type;
        string title = "";
        string starttime = "";
        string endtime = "";
        MsSqlDal<Notice> iNotice = new MsSqlDal<Notice>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["Type2"] != null)
                {
                    if (Request.Params["limit"] != null && Request.Params["start"] != null)
                    {

                        type = Convert.ToInt32(Request.Params["Type2"]);
                        if (type == 1)
                        {
                            if (Request.Params["Title"] != null)
                            {
                                title = Request.Params["Title"];
                            }
                            PageBean pb = new PageBean();
                            IList<model.Notice> list = iNotice.GetPageList("Title like '%" + title + "%' and typeid = 2", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            IList<Notice> nList = new List<Notice>();
                            foreach (Notice info in list)
                            {
                                info.AddUser = MyGet.GetUserInfoByID(info.AddUser).Name;
                                nList.Add(info);
                            }
                            pb.Count = iNotice.GetPageCount("Title like '%" + title + "%' and typeid = 2", null);
                            pb.List = nList;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                        else
                        {

                            if (Request.Params["StartTime"] != null)
                            {
                                starttime = Request.Params["StartTime"];

                            }
                            if (Request.Params["endtime"] != null)
                            {
                                endtime = Request.Params["endtime"];
                            }
                            PageBean pb = new PageBean();
                            IList<model.Notice> list = iNotice.GetPageList("AddTime between '" + starttime + "' and '" + endtime + "' and typeid = 2", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            IList<Notice> nList = new List<Notice>();
                            foreach (Notice info in list)
                            {
                                info.AddUser = MyGet.GetUserInfoByID(info.AddUser).Name;
                                nList.Add(info);
                            }
                            pb.Count = iNotice.GetPageCount("AddTime between '" + starttime + "' and '" + endtime + "' and typeid = 2", null);
                            pb.List = nList;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                    }
                }
                else
                {
                    if (Request.Params["limit"] != null && Request.Params["start"] != null && Request.Params["TypeID"] != null)
                    {

                        IList<Notice> List = iNotice.GetPageList("TypeID=" + Request.Params["TypeID"], null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        IList<Notice> nList = new List<Notice>();
                        foreach (Notice info in List)
                        {
                            info.AddUser = MyGet.GetUserInfoByID(info.AddUser).Name;
                            nList.Add(info);
                        }
                        PageBean pb = new PageBean();
                        pb.Count = iNotice.GetPageCount("TypeID=" + Request.Params["TypeID"], null);
                        pb.List = nList;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                }
            }
            else
            {
                Response.Write("{'Count':0,'List':[]}");
            }
        }
    }
}